home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
polyview
/
polyvw31.lha
/
Polyview3.1
/
new
/
mkproto.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-23
|
4KB
|
140 lines
/* $Header: /usr3/people/gbourhis/pv3/new/RCS/mkproto.c,v 1.1 92/09/18 10:55:26 marca Exp $ */
#ifdef RCSLOG
$Log: mkproto.c,v $
* Revision 1.1 92/09/18 10:55:26 marca
* Initial revision
*
#endif
#include <string.h>
#include <stdio.h>
/* mkproto.c
Marc Andreessen, NCSA
Syntax: ./mkproto filenames
Given filenames for C source files, scans each in turn
and dumps prototypes for all non-static functions to stdout.
Assumes reasonable indentation practices are being followed. */
#define DUMP_LINE(l) \
{ \
int i = strlen(l); \
if (l[i-2] == ')') \
{ \
l[i-1] = ';'; \
l[i] = '\n'; \
l[i+1] = '\0'; \
} \
fprintf (stdout, "%s", l); \
}
/* Copies "source" to "dest", substituting the value of "new" for all */
/* occurrences of the value "old". Assumes sizeof(dest) > strlen(source)- */
/* strlen(old)+strlen(new). Always returns the value of dest. */
char *strsub (char *dest, char *source, char *old, char *new)
{
char *start, *next;
/* Initialize the pointers to the beginning of their buffers. */
start = source;
*dest = '\0';
/* Keep copying as long as there are matches. */
while (next = strstr(start, old)) {
/* Copy the part of the source that was skipped over. */
strncat(dest, start, (size_t) (next-start));
/* Substitute the new string. */
strcat(dest, new);
/* Change the starting point of our search. */
start = next + strlen(old);
}
/* Append the rest of the source. */
strcat(dest, start);
return dest;
}
void process_file (char *fname)
{
FILE *fp;
char line[240], oldline[240];
int done;
fp = fopen (fname, "r");
if (fp == NULL)
{
fprintf (stderr, "mkproto: No file %s.\n", fname);
return;
}
fprintf (stdout, "/* THIS FILE IS AUTOMATICALLY GENERATED by mkproto. */\n");
/* Dump the filename to a comment. */
fprintf (stdout, "\n/* %s */\n\n", fname);
while (!feof (fp))
{
/* Fetch a new line. */
fgets (line, 240, fp);
/* Determine whether the line begins a function. */
if (!(strncmp (line, "main", 4) == 0 ||
strncmp (line, "void main", 9) == 0 ||
strncmp (line, "int main", 8) == 0 ||
strncmp (line, "static", 6) == 0 ||
strncmp (line, "extern", 6) == 0)
&&
((line[0] >= 'a' && line[0] <= 'z') ||
(line[0] >= 'A' && line[0] <= 'Z') ||
(line[0] == '_'))
&&
(strstr (line, "(") != NULL))
{
/* Make substitutions on the line as appropriate. */
bcopy (line, oldline, 240);
strsub (line, oldline, "XmxCallback", "XmxCallbackPrototype");
bcopy (line, oldline, 240);
strsub (line, oldline, "XmxEventHandler",
"XmxEventHandlerPrototype");
/* Dump the first line. */
done = (line[strlen(line)-2] == ')');
DUMP_LINE (line);
/* While there are lines remaining in this prototype,
dump them. */
while (!feof (fp) && !done)
{
fgets (line, 240, fp);
done = (line[strlen(line)-2] == ')');
DUMP_LINE (line);
}
}
}
fclose (fp);
return;
}
main (int argc, char **argv)
{
while (--argc)
{
++argv;
/* Here argv[0] is a filename. */
process_file (argv[0]);
}
}